﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Aliyeye.Car.Net.Utility;

namespace Aliyeye.Car.Net.Dal
{
    public class Accounts_Roles
    {
        public Accounts_Roles() { }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.Accounts_Roles model)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@RoleID", SqlDbType.Int,4),
                    new SqlParameter("@Description", SqlDbType.VarChar,255)};
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = model.Description;
            int roleId = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "Accounts_Roles_ADD", parameters);
            if (roleId > 0)
            {
                return roleId;
            }
            else
            {
                return 0;
            }
        }

        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RoleID,Description FROM Accounts_Roles ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return SqlHelper.Query(strSql.ToString());
        }

        public bool Update(Model.Accounts_Roles model)
        {
            bool result = false;
            SqlParameter[] parameters = {
                    new SqlParameter("@RoleID", SqlDbType.Int,4),
                    new SqlParameter("@Description", SqlDbType.VarChar,255)};
            parameters[0].Value = model.RoleID;
            parameters[1].Value = model.Description;
            int roleId = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "Accounts_Roles_Update", parameters);
            if (roleId > 0)
            {
                result = true;
            }
            else
            {
                result = false;
            }
            return result;
        }

        public bool Delete(Model.Accounts_Roles model)
        {
            bool result = false;
            SqlParameter[] parameters = {
                    new SqlParameter("@RoleID", SqlDbType.Int,4)};
            parameters[0].Value = model.RoleID;
            int roleId = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "Accounts_Roles_Delete", parameters);
            if (roleId > 0)
            {
                result = true;
            }
            else
            {
                result = false;
            }
            return result;
        }
    }
}
